##!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import reduce


def str2float(s):
    i = 0
    for c in s:
        if c == '.':
            break
        else:
            i = i + 1

    news = s[:i] + s[i + 1:]

    def integer(x, y):
        return x * 10 + y

    def strToNum(x):
        d = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
        return d[x]

    num = reduce(integer, map(strToNum, news)) / pow(10, i)

    return num


print('str2float(\'123.456\') =', str2float('123.456'))
if abs(str2float('123.456') - 123.456) < 0.00001:
    print('测试成功!')
else:
    print('测试失败!')
